<?php
/**
 * Модель param
 * 
 * Класс модели
 * @author Anton Zavidov
 * @package myLiveShop
 */

/**
 * Модель param
 *
 */
class ModelParam extends Model {
	
	const TABLE				= 'param';
	const F_PARAM_ID  	= 'param_id';
	const F_CATEGORY_ID  	= 'category_id';
	const F_TYPE  	= 'type';
	const F_VALUES  	= 'values';
	const F_SIZE  	= 'size';
	const F_SORT  	= 'sort';
	const F_TITLE  	= 'title';
	const F_DESCRIPTION  	= 'description';
	const F_LANG_ID  	= 'lang_id';
	const F_TO_ORDER  	= 'to_order';
			
	public function __construct($className=null){
		parent::__construct(__CLASS__);
		$this->name='param';
		$this->id_field=array(self::F_PARAM_ID);
		$this->fields=array(
		self::TABLE.DOT.self::F_PARAM_ID=> new Field($this,self::F_PARAM_ID,self::TABLE,array(
				'auto'=>true,
				'important'=>true,
				'lenght'=>9)),
		self::TABLE.DOT.self::F_CATEGORY_ID=> new Field($this,self::F_CATEGORY_ID,self::TABLE,array(
				'lenght'=>11,
				'join_table'=>'category')),
		self::TABLE.DOT.self::F_TYPE=> new Field($this,self::F_TYPE,self::TABLE,array(
				'lenght'=>2)),
		self::TABLE.DOT.self::F_VALUES=> new Field($this,self::F_VALUES,self::TABLE,array(
				'lenght'=>255,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_SIZE=> new Field($this,self::F_SIZE,self::TABLE,array(
				'lenght'=>20,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_SORT=> new Field($this,self::F_SORT,self::TABLE,array(
				'lenght'=>3)),
		self::TABLE.DOT.self::F_TITLE=> new Field($this,self::F_TITLE,self::TABLE,array(
				'lenght'=>50,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_DESCRIPTION=> new Field($this,self::F_DESCRIPTION,self::TABLE,array(
				'lenght'=>255,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_LANG_ID=> new Field($this,self::F_LANG_ID,self::TABLE,array(
				'lenght'=>2,
				'join_table'=>'lang')),
		self::TABLE.DOT.self::F_TO_ORDER=> new Field($this,self::F_TO_ORDER,self::TABLE,array(
				'lenght'=>1,
				'validate_type'=>Validator::VALIDATE_BOOL))		);
	}

	/**
	 * список параметров по id категории
	 *
	 * @param int $category_id
	 * @return array
	 */
	public function getByCategoryId($category_id){
	     return $this->load(false,"*",array(
				'where'=>self::F_CATEGORY_ID.'='.$category_id,
				'order'=>self::F_SORT
			)
		);
	}
}
